What Can You Do with the Run Command?
The RUN command runs a Windows or DOS executable program, a Liberty BASIC TKN or a BAT file. The syntax is as follows:
RUN ExeName$ [, mode ]
ExeName$
The name of the executable file to be run must include the full path unless it is contained in the same directory as the program from which it is run. In the following example, the TKN file is in the same directory as the program that runs it.
run "mytkn.tkn"
A path designation is not needed if the executable is a program typically included in a Windows installations, such as Notepad. In that case, you must know the correct executable name. For example, the Windows calculator has an exe name of "calc.exe." If the extension ".exe" is not appended to the filename, it is assumed. Here are some examples of the RUN command:
run "calc.exe" run "calc" run "notepad" run "mspaint"
Commandline Parameters
To run an executable with a file loaded, simply include the filename after the name of the executable. This example, when run from the Liberty BASIC 3.03 root directory, runs Notepad with the "newfor303.txt" file loaded:
run "notepad newfor303.txt"
Long filenames contain spaces. If a full path and filename designation is used, place it inside of double quotation marks, which are chr$(34), and append the string to the name of the executable. Be sure to leave a blank space after the executable's name.
run "notepad " + chr$(34) + DefaultDir$ + "\myfile.txt" + chr$(34)
Mode
The MODE argument is optional. If used, a comma must follow the string containing the executable name and commandline parameters. After the comma, specify the desired run MODE. You may select one of the following MODEs for running Windows programs, along with a brief description of each:
HIDE (activates the application, but hides it from the user)
SHOWNORMAL (this is the default - activates and shows the application)
SHOWMINIMIZED (activates the application, but minimizes it to the taskbar)
SHOWMAXIMIZED (activates the application in a full screen window)
SHOWNOACTIVE (shows a window in its most recent size and position without activating it)
SHOW (activates an application and shows it in its current size and position)
MINIMIZE (minimizes a window and activates the next window in the Z order)
SHOWMINNOACTIVE (minimizes an application, leaving the current active window active)
SHOWNA (displays the window in its current state. the active window remains active)
RESTORE (activates the application and displays the window)
Running the Windows Shell
The Windows shell is called Windows Explorer and its filename is "explorer.exe". We can use it to run the default applications associated with file extensions on the user's computer. For instance, most people have the extension "txt" associated with Notepad. Some folks prefer to use alternate text editors. To display a text file in the user's default text editor, do this:
run "explorer " + chr$(34) + DefaultDir$ + "\myfile.txt" + chr$(34)
Here are some examples that allow the user to select a file. The program then uses Windows Explorer to run the correct application associated with that file.
filedialog "Open","*.bmp",bmp$ run "explorer " + chr$(34) + bmp$ + chr$(34) filedialog "Open","*.*",file$ run "explorer " + chr$(34) + file$ + chr$(34)
Commandline Switches
Some programs use commandline switches. In issue #103, we discussed the use of the /p switch with MS Paint to cause a hard copy of a designated bitmap to be printed by mspaint.exe. Here is a small, working demo of that technique.
filedialog "Open","*.bmp",BmpFile$ run "mspaint.exe " + BmpFile$ + " /p", HIDE
The available switches depend on the application being run.
Running Liberty BASIC from the Commandline
The newsletter has run a series of tutorials that built and modified a program editor written in Liberty BASIC called the Open Source Editor. It began life in issue #58 and that issue contains information on running a file using Liberty BASIC and it's commandline switches. They are:
COMMANDLINE SWITCHES -R Run a BAS file on startup -D Debug a BAS file on startup --------the following three are in the registered version only-------- -T Make a TKN file from a BAS file on startup -A Automatically Exit LB on completion of BAS file -M Minimize the Liberty BASIC editor on startup
Examples:
LIBERTY -R -M PROG.BAS 'run PROG.BAS with editor minimized
LIBERTY -T -A PROG.BAS 'create a TKN file from PROG.BAS then exit
LIBERTY -D PROG.BAS 'run the debugger on PROG.BAS
An example in Liberty BASIC syntax:
RUN "LIBERTY.EXE -R boxes.bas"